//
// Copyright (c) 2024 BPer
//

#include <bperutil/buffer/BPerAudioBuffer.h>


BPerAudioBuffer::BPerAudioBuffer(int32_t pcacheNum)
{
	resetIndex();
	m_cache_num=pcacheNum;
	m_bufLen=0;
}

void BPerAudioBuffer::reset(){
	resetIndex();
}

BPerAudioBuffer::~BPerAudioBuffer(void)
{

}

void BPerAudioBuffer::putAudio(BPerFrame* pframe)
{
	if(m_bufLen==0){
		m_bufLen=pframe->nb;
		initFrames(m_cache_num,pframe->nb);
	}
	putFrame(pframe);

}

int32_t BPerAudioBuffer::getAudio(BPerFrame* pframe)
{
    if(size()>0){
    	getFrame(pframe);
        return 0;
    }else
        return 1;
}


uint8_t *BPerAudioBuffer::getAudioRef(BPerFrame* pframe)
{
    if(size()>0){
    	return getFrameRef(pframe);
    }else{
        return NULL;
    }
}

